﻿
@{
    ViewBag.Title = "BidEditView";
    Layout = "~/Views/Shared/_MyLayout.cshtml";
}


<div style="margin-top:10px;">
    <form class="layui-form" id="FormInfo">
        <div class="layui-form-item">
            <label class="layui-form-label">项目编号</label>
            <div class="layui-input-inline">
                <input type="text" name="ProJectCode" value="@ViewBag.ProJectCode"  placeholder="请输入编号" autocomplete="off" class="layui-input">
            </div>
            <label class="layui-form-label">项目名称</label>
            <div class="layui-input-inline" style="width:400px;">
                <input type="text" name="Name" value="@ViewBag.Name" required lay-verify="required" placeholder="请输入项目名称" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">投标时间</label>
            <div class="layui-input-inline">
                <input type="text" name="BidTime" value="@ViewBag.BidTime" id="BidTime" required lay-verify="required" placeholder="请输选择时间" autocomplete="off" class="layui-input">
            </div>
            <label class="layui-form-label">投标状态</label>
            <div class="layui-input-inline">
                <select name="BidState" lay-verify="required" required lay-filter="BidStateSelFilter">
                    <option value=""></option>
                    <option value="0">评标</option>
                    <option value="1">流标</option>
                    <option value="2">中标</option>
                </select>
            </div>
            <label class="layui-form-label">项目类型</label>
            <div class="layui-input-inline">
                <input type="text" name="type" value="@ViewBag.type"  placeholder="主业|用户工程" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">投标金额</label>
            <div class="layui-input-inline">
                <input type="number" name="BidAmount" value="@ViewBag.BidAmount" required lay-verify="required" placeholder="投标金额" autocomplete="off" class="layui-input">
            </div>
            <label class="layui-form-label">中标金额</label>
            <div class="layui-input-inline">
                <input type="number" name="WinnAmount" value="@ViewBag.WinnAmount" placeholder="中标金额" autocomplete="off" class="layui-input">
            </div>
            <label class="layui-form-label">中标单位</label>
            <div class="layui-input-inline"  style="width:300px;">
                <input type="text" name="WinnName" value="@ViewBag.WinnName" placeholder="中标单位" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="submit" id="mysubmit" class="layui-btn" lay-submit lay-filter="formVerify" style="display:none;">立即提交</button>
                <button type="button" class="layui-btn" id="BtnSave">保存</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>

<script>
    var ProjectId = "@ViewBag.ProjectId";
    var BidState = "@ViewBag.BidState";
    layui.use([ 'form', 'laydate'], function(){
        var form = layui.form;
        var laydate = layui.laydate;
        var IsValidate = 0;

        //选中下拉菜单
        if (BidState != "") {
            $("select[name=BidState]").find("option[value='" + BidState + "']").attr("selected", true);
            form.render();
            //layui.form().render(); //这是1.0的写法
            //layui.form.render();  //这是2.0更新后的写法
            //$("#myselect").val(state);
        }

        form.on('select(BidStateSelFilter)', function (data)
        {
            //console.log(data.elem); //得到select原始DOM对象
            //console.log(data.value); //得到被选中的值
            //console.log(data.othis); //得到美化后的DOM对象
            switch (data.value) {
                case "2":
                    //layer.confirm('当前选项保存后，将把项目移动到中标栏', { icon: 3, title: '提示' }, function (index)
                    //{
                    //    //do something
                    //    $("select[name=BidState]").find("option[value='1']").attr("selected", true);
                    //    form.render('select','BidStateSelFilter');
                    //    layer.close(index);
                    //});
                    //$("select[name=BidState]").prop("selected", false);
                    //form.render();
                    parent.layer.msg('当前选项保存后，将把项目移动到中标栏', { icon: 6, time: 2000 });
                    break;
                default:

            }
        }); 

        //拦截form提交消息
        form.on('submit(formVerify)', function (data) {
            //layer.msg(JSON.stringify(data.field));
            IsValidate = 1;
            return false;
        });

        laydate.render({
            elem: '#BidTime' //指定元素
        });

        $("#BtnSave").on("click", function () {

            $("#mysubmit").click();
            if (IsValidate == 1) {
                var obj = $("#FormInfo").serializeArray();
                var data = {};
                $.each(obj, function (i, v) {
                    data[v.name] = v.value;
                });
                if (ProjectId == "") {
                    //表示新增
                    $.ajax({
                        type: "POST",
                        url: "/Project/BidInfoAdd",
                        async: false,
                        contentType: "application/json",
                        dataType: "json",
                        data: JSON.stringify(data),
                        success: function (msg) {
                            if (msg.result == "OK") {
                                parent.layer.msg('新增成功', { icon: 6, time: 1000 });
                                //parent.table.reload("demo");
                                //var index = parent.layer.getFrameIndex(window.name);
                                //parent.layer.close(index);

                                parent.layui.admin.events.closeThisTabs();
                            } else {
                                alert(msg.result);
                            }
                        }
                    });


                }
                else {
                    //表示编辑
                    data["ProjectId"] = ProjectId;
                    $.ajax({
                        type: "POST",
                        url: "/Project/BidInfoUpdate",
                        async: false,
                        contentType: "application/json",
                        dataType: "json",
                        data: JSON.stringify(data),
                        success: function (msg) {
                            if (msg.result == "OK") {
                                parent.layer.msg('修改成功', { icon: 6, time: 1000 });
                                //parent.table.reload("demo");
                                //var index = parent.layer.getFrameIndex(window.name);
                                //parent.layer.close(index);

                                parent.layui.admin.events.closeThisTabs();
                            } else {
                                alert(msg.result);
                            }
                        }
                    });
                }
            }
        });









    });
</script>

